package com.zzh.wsss.service.impl;

import com.zzh.wsss.mapper.UserOperateMapper;
import com.zzh.wsss.pojo.User;
import com.zzh.wsss.service.UserInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserInterfaceServiceImpl implements UserInterfaceService {

    @Autowired
    private UserOperateMapper userOperateMapper;

    public User getuserid(String username) {
        return userOperateMapper.getUserId(username);
    }

    public void setuserheadportrait(String username,String filename) {
        userOperateMapper.SetUserHeadportrait(username,filename);
    }

    public void setusernickname(String username, String nickname) {
        userOperateMapper.SetUserNickname(username,nickname);
    }

    public Boolean updatapassword(String username,String oldpassword, String newpassword) {
        List<User> list=userOperateMapper.getPassword(username);
        if(list.size()==0)return false;
        User user=list.get(0);
        if(user.getPassword().equals(oldpassword)){
            userOperateMapper.SetUserPassword(username,newpassword);
            return true;
        }else return false;

    }
}
